﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.Xml;
using System.Xml.Xsl;

public partial class KMrpt10 : ExtBaseRpt
{

    protected void Page_Load(object sender, EventArgs e)
    {
        mid = Request.Params["mid"];
        if (!X.IsAjaxRequest)
        {
            BuildGridPanel(this.GridPanel1, mid, Session["UserID"].ToString());
            this.txtbdate.Text = DateTime.Now.ToString("yyyy-MM-01");
            this.txtedate.Text = DateTime.Now.ToString();
            //this.txtbjhdate.Text = DateTime.Now.ToString("yyyy-MM-01");
            //this.txtejhdate.Text = DateTime.Now.ToString();
        }
    }
   
    protected void BtnQureyUser(object sender, DirectEventArgs e)
    {
        string bdate, edate;
        if (Convert.ToDateTime(txtbdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            bdate = "";
        else
            bdate = txtbdate.Text;

        if (Convert.ToDateTime(txtedate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            edate = "";
        else
            edate = txtedate.Text;

        //if (Convert.ToDateTime(txtbjhdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
        //    sjhdaate = "";
        //else
        //    sjhdaate = txtbjhdate.Text;

        //if (Convert.ToDateTime(txtejhdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
        //    ejhdaate = "";
        //else
        //    ejhdaate = txtejhdate.Text;

        this.Store1.DataSource = db.DM_GetDateSet("KM_PurDetailBarCode '"+txtyear.Text+"','"+txtseason.Text+"','" 
            + bdate + "','" + edate + "','"+txtvcode.Text+"','"+txtvname.Text+"','"+txtstyleno.Text+"','billdate'");
        this.Store1.DataBind();
    }


    protected void RefreshDataSet(object sender, StoreReadDataEventArgs e)
    {
        BtnQureyUser(null,null);
    }
    protected void Store1_Submit(object sender, StoreSubmitDataEventArgs e)
    {
        //导出EXCEL
        ExtGridToExcel(mid,"xls",e.Xml,this.Response,this.Title);
    }

    protected void ToExcel(object sender, EventArgs e)
    {
        InsActLog(mid,"导出");
        string json = this.Hidden1.Value.ToString();
        StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
        XmlNode xml = eSubmit.Xml;

        this.Response.Clear();
        this.Response.ContentType = "application/vnd.ms-excel";
        this.Response.AddHeader("Content-Disposition", "attachment; filename="+this.Title+".xls");

        XslCompiledTransform xtExcel = new XslCompiledTransform();

        xtExcel.Load(Server.MapPath("Excel.xsl"));
        xtExcel.Transform(xml, null, this.Response.OutputStream);
        this.Response.End();
    }
}